package huawei;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * 规则麻烦，条件杂
 *
 * @Author Jun jie Yi
 * 2022/4/3 15:22
 */
public class Demo {

    static List<Integer> cds = Arrays.asList(128, 192, 224, 240, 248, 252, 254, 255);

    public static void main(String[] args) {
        //1. 获取输入数据
        Scanner in = new Scanner(System.in);
        //2. A、B、C、D、E、错误IP地址或错误掩码、私有IP的个数
        int[] logs = new int[7];
        while (in.hasNextLine()) {
            String s = in.nextLine();
            if ("".equals(s)) {
                continue;
            }
            if (!s.contains("~")) continue;
            String[] split = s.split("~");//0为ip,1为子网掩码
            //转换为数值
            verify(split[0], split[1], logs);
            //打印logs
        }
        for (int i = 0; i < logs.length; i++) {
            if (i < logs.length - 1) {
                System.out.print(logs[i] + " ");
            } else {
                System.out.print(logs[i]);
            }
        }
    }

    //验证 ip 的合法性和ip的类型
    public static void verify(String ip_str, String cd_str, int[] logs) {
        int[] ip = new int[4];
        String[] s = ip_str.split("\\.");
        if ("0".equals(s[0]) || "127".equals(s[0])) {
            return;
        }
        //子网掩码非法直接 +1
        if (verifyCd(cd_str) == false) {
            logs[5]++;
            return;
        }
        for (int i = 0; i < 4; i++) {
            try {
                ip[i] = Integer.parseInt(s[i]);
            } catch (Exception e) {
                logs[5]++;
                return;
            }
        }
        //A B C D E 判断
        if (ip[0] >= 1 && ip[0] <= 126) {
            logs[0]++;
            //私有ip判断
            if (ip[0] == 10) logs[6]++;
        } else if (ip[0] >= 128 && ip[0] <= 191) {
            logs[1]++;
            //私有ip判断
            if (ip[0] == 172 && ip[1] >= 16 && ip[1] <= 31) logs[6]++;
        } else if (ip[0] >= 192 && ip[0] <= 223) {
            logs[2]++;
            //私有ip判断
            if (ip[0] == 192 && ip[1] == 168) logs[6]++;
        } else if (ip[0] >= 224 && ip[0] <= 239) {
            logs[3]++;
        } else if (ip[0] >= 240 && ip[0] <= 255) {
            logs[4]++;
        }
    }

    //子网掩码验证
    public static boolean verifyCd(String cd_str) {
        int[] cd = new int[4];
        String[] s = cd_str.split("\\.");
        for (int i = 0; i < 4; i++) {
            try {
                cd[i] = Integer.parseInt(s[i]);
            } catch (Exception e) {
                //转换数字不成功直接错
                return false;
            }
        }
        //是否是合格的子网掩码
        for (int i = 3; i >= 0; i--) {
            if (cd[i] == 0) {
                continue;
            } else if (cds.contains(cd[i])) {
                //验证前面的是否都是255
                for (int j = 0; j < i; j++) {
                    if (cd[j] != 255) {
                        return false;
                    }
                }
            } else {
                //不合法
                return false;
            }
        }
        return true;
    }
}
